
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import { WebView } from 'react-native-webview';
import {Util,ifIphoneX} from './util'
const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class TwebView extends Component<Props> {
  static  navigationOptions=({navigation,navigationOptions}) => {
    return {
      title: navigation.getParam('title'),
    };
  };

  constructor(props){
    const {navigation,url} = props;
    let Url = url?url:navigation.getParam('url');
    super(props);
    this.state = {
      url: Url,
      isError: false,
    }
  }
  render() {
    return (
        <View style={styles.contaniner}>
          {
            this.state.isError ? <View style={styles.errorInfo}>
              <Text style={styles.text}>网络有问题，请检查网络情况,再刷新</Text>
            </View> : <WebView
                onError={this._showError.bind(this)}
                startInLoadingState={true}
                source={{uri: this.state.url}}
                 />
          }
        </View>

    );
  }
  _showError() {
    this.setState({
      isError: true
    })
  }
}

const  styles = StyleSheet.create({
  contaniner: {
    flex: 1,
  },
  errorInfo: {
    flex:1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  text:{
    fontSize: 16,
    fontWeight: '300',
  }

});
